<template>
    <div>
        <!-- 首页 -->
        <el-row :gutter="20">
            <template v-if="topList.length == 0">
                <el-col :span="6" v-for="i in 4" :key="i">
                    <el-skeleton style="width: 100%;" animated loading>
                        <template #template>
                            <el-card shadow="hover" class="border-0">
                                <template #header>
                                    <div class="flex justify-between">
                                        <el-skeleton-item variant="text" style="width: 50%" />
                                        <el-skeleton-item variant="text" style="width: 10%" />
                                    </div>
                                </template>
                                <el-skeleton-item variant="h3" style="width: 80%" />
                                <el-divider />
                                <div class="flex justify-between text-sm text-gray-500">
                                    <el-skeleton-item variant="text" style="width: 50%" />
                                    <el-skeleton-item variant="text" style="width: 10%" />
                                </div>
                            </el-card>
                        </template>
                    </el-skeleton>
                </el-col>
            </template>
            <el-col :span="6" v-for="item in topList" :key="item.value">
                <el-card class="box-card" shadow="hover">
                    <template #header>
                        <div class="flex justify-between text-sm">
                            <span>{{item.title}}</span>
                            <el-tag :type="item.unitColor">{{item.unit}}</el-tag>
                        </div>
                    </template>
                    <div class="text item font-bold ">
                        <span class="text-3xl text-left">
                            <!-- {{item.value}} -->
                            <NumberRoll :value="item.value"></NumberRoll>
                        </span>
                    </div>
                    <el-divider />
                    <div class="flex justify-between text-sm">
                        <span>{{item.subTitle}}</span>
                        <span>{{item.subValue}}</span>
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <div class="mt-5">
            <HomeNav></HomeNav>
        </div>
        <div class="mt-5">
            <el-row :gutter="20">
                <el-col :span="12">
                    <HomeChart v-permission="['getStatistics3,GET']"></HomeChart>
                </el-col>
                <el-col :span="12">
                    <HomeCard class="mb-5"  title="店铺及商品提示" tip="店铺及商品提示" :btns="cardList1"></HomeCard>
                    <HomeCard title="交易提示" tip="需要立即处理的交易订单" :btns="cardList2"></HomeCard>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script setup>
import { getStatistics1, getCardList } from '@/api/home.js'
import { ref, onMounted } from 'vue'
import NumberRoll from '@/components/Home/NumberRoll.vue'
import HomeNav from '@/components/Home/HomeNav.vue'
import HomeChart from '@/components/Home/HomeChart.vue'
import HomeCard from '@/components/Home/HomeCard.vue'

const topList = ref([])
getStatistics1().then(res => {
    topList.value = res.data.panels
})
const cardList1 = ref([])
const cardList2 = ref([])

getCardList().then(res => {
    cardList1.value = res.data.goods
    cardList2.value = res.data.order
})


</script>

<style>
.text {
    font-size: 14px;
}

.item {
    margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both
}
</style>